Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: Fix adding vector index on empty table may blocked forever #9470

Merged

Conversation

JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Sep 25, 2024

What problem does this PR solve?

Issue Number: ref #9032

Problem Summary:

When creating vector index on empty table, the DDL may be blocked forever.

This is because when an empty table is synced to TiFlash, the StorageDeltaMerge is created without initializing the DeltaMergeStore instance. This is to avoid generating too many fragmented, small files that exhaust the filesystem inode.
However, if the DeltaMergeStore instance is not created, then system.dt_local_index will not get the local index stats. Which make tidb consider the vector index is still under building and the ddl does not end.

auto dm_storage = std::dynamic_pointer_cast<StorageDeltaMerge>(storage);
const auto & table_info = dm_storage->getTableInfo();
auto table_id = table_info.id;
auto store = dm_storage->getStoreIfInited();
if (!store)
continue;

What is changed and how it works?


  • If StorageDeltaMerge is created but DeltaMergeStore is not inited, then generate the local index info by the TiDB::TableInfo

Small refactor:

  • Remove a verbose logging when system table is read by tidb-server

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 25, 2024
@@ -243,7 +243,6 @@ void InterpreterSelectQuery::getAndLockStorageWithSchemaVersion(const String & d
|| (managed_storage->engineType() != ::TiDB::StorageEngine::DT
&& managed_storage->engineType() != ::TiDB::StorageEngine::TMT))
{
LOG_DEBUG(log, "{}.{} is not ManageableStorage", database_name, table_name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running queries on the system table will trigger this logging, which is verbose but not provide any information. Remove it.

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 25, 2024
@JaySon-Huang JaySon-Huang changed the title [WIP] ddl: Fix adding vector index on empty table may blocked forever ddl: Fix adding vector index on empty table may blocked forever Sep 25, 2024
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 25, 2024
@Lloyd-Pottiger
Copy link
Contributor

Why not just insert a row even when store is not init?

@breezewish
Copy link
Member

Not sure whether this idea is ok, we may also regard progress=1 and missing table in tiflash_indexes as index build is finished, because progress=1 already means TiFlash is aware of this table, and then no entry in tiflash_indexes means exactly this case?

@JaySon-Huang
Copy link
Contributor Author

JaySon-Huang commented Sep 25, 2024

Not sure whether this idea is ok, we may also regard progress=1 and missing table in tiflash_indexes as index build is finished, because progress=1 already means TiFlash is aware of this table, and then no entry in tiflash_indexes means exactly this case?

@breezewish No, we can not tell the difference between these two cases

  • A table without any vector index but the tiflash replica is already built
  • A table with the tiflash replica is already built, tidb added a vector index definition to the table, but tiflash is not aware that the vector index has been added

@JaySon-Huang
Copy link
Contributor Author

@Lloyd-Pottiger DeltaMergeStore::getLocalIndexStats requires a DeltaMergeStore instance to get the stats of local indexes. Without that result, we are hard to tell wihch index_id need to be added to dt_local_index

auto store = dm_storage->getStoreIfInited();
if (!store)
continue;
if (dm_storage->isTombstone())
continue;
auto index_stats = store->getLocalIndexStats();

@Lloyd-Pottiger
Copy link
Contributor

@Lloyd-Pottiger DeltaMergeStore::getLocalIndexStats requires a DeltaMergeStore instance to get the stats of local indexes. Without that result, we are hard to tell wihch index_id need to be added to dt_local_index

auto store = dm_storage->getStoreIfInited();
if (!store)
continue;
if (dm_storage->isTombstone())
continue;
auto index_stats = store->getLocalIndexStats();

The index info can get from table info, and the rows indexed is 0.

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 26, 2024
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 26, 2024
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 26, 2024
@wuhuizuo
Copy link
Contributor

/retest

@JaySon-Huang
Copy link
Contributor Author

@Lloyd-Pottiger @JinheLin PTAL

Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Sep 27, 2024
@Lloyd-Pottiger
Copy link
Contributor

Need to update description.

@JaySon-Huang
Copy link
Contributor Author

Need to update description.

Updated

Copy link
Contributor

ti-chi-bot bot commented Sep 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JinheLin, Lloyd-Pottiger

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JinheLin,Lloyd-Pottiger]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 29, 2024
Copy link
Contributor

ti-chi-bot bot commented Sep 29, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-09-27 12:06:40.027206939 +0000 UTC m=+10955.447419944: ☑️ agreed by Lloyd-Pottiger.
  • 2024-09-29 03:42:26.686555973 +0000 UTC m=+153502.106768987: ☑️ agreed by JinheLin.

@ti-chi-bot ti-chi-bot bot merged commit cd204f5 into pingcap:feature/vector-index Sep 29, 2024
5 checks passed
@JaySon-Huang JaySon-Huang deleted the fix_store_not_init branch September 29, 2024 03:54
@JaySon-Huang JaySon-Huang mentioned this pull request Sep 30, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants